Skip to content

fix: handle optional chaining for imports in setupImportMocking function#1433

Merged
danielroe merged 1 commit intonuxt:mainfrom
ExEr7um:main
Oct 23, 2025
Merged

fix: handle optional chaining for imports in setupImportMocking function#1433
danielroe merged 1 commit intonuxt:mainfrom
ExEr7um:main

Conversation

@ExEr7um
Copy link
Copy Markdown
Contributor

@ExEr7um ExEr7um commented Oct 3, 2025

🔗 Linked issue

None.

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Problem

The setupImportMocking function was failing when presets contained string values (e.g., vitest) instead of objects with an imports property.

export default defineNuxtConfig({
  imports: { presets: ["vitest"] },
})

This caused a TypeError when trying to access p.imports on string presets, breaking test execution.

⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯
TypeError: Cannot read properties of undefined (reading 'includes')

Solution

Added optional chaining (?.) to safely check if the imports property exists before calling .includes('setInterval'). This prevents errors when presets are strings rather than objects with an imports array.

@ExEr7um ExEr7um requested a review from danielroe as a code owner October 3, 2025 16:48
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Oct 3, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/test-utils@1433

commit: 2b351f1

@danielroe danielroe merged commit 31a7637 into nuxt:main Oct 23, 2025
7 checks passed
@github-actions github-actions bot mentioned this pull request Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants